from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton
from PyQt5.QtGui import QIntValidator


class NewParams:
    def __init__(self, pid_count, successListener):
        self.pid_count = pid_count
        self.successListener = successListener


def CreateNewWindow(screen, new_Params, ui_main):
    win = QDialog()
    win.setWindowFlags(Qt.WindowCloseButtonHint)
    win.setWindowTitle('新建进程')
    width = 400
    height = 300
    win.setGeometry((screen.width - width) / 2, (screen.height - height) / 2, width, height)

    outline_vg = QVBoxLayout()

    text_process = QLabel("进程号: {}".format(new_Params.pid_count))
    outline_vg.addWidget(text_process)

    text_subline = QLabel("--------------------")
    outline_vg.addWidget(text_subline)

    text_arrival = QLabel("到达时间: ")
    outline_vg.addWidget(text_arrival)

    input_arrival = QLineEdit("")
    input_arrival.setValidator(QIntValidator())
    outline_vg.addWidget(input_arrival)

    text_work = QLabel("服务时间: ")
    outline_vg.addWidget(text_work)

    input_work = QLineEdit("")
    input_work.setValidator(QIntValidator())
    outline_vg.addWidget(input_work)

    ok_button = QPushButton("确定")
    ok_button.clicked.connect(
        lambda: new_Params.successListener(win, input_arrival.text(), input_work.text(), ui_main))
    outline_vg.addWidget(ok_button)

    outline_vg.addStretch()
    win.setLayout(outline_vg)
    return win
